package com.xuecheng.content.api;

import com.xuecheng.base.Validate.ValidateGroups;
import com.xuecheng.base.model.PageParam;
import com.xuecheng.content.Utils.SecurityUtil;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseBaseInfoDto;
import com.xuecheng.content.model.dto.QueryCourseParamDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.model.po.PageResult;
import com.xuecheng.content.service.CourseBaseService;
import com.xuecheng.content.service.SelectCourseBaseService;
import com.xuecheng.content.service.impl.CreateCourseBaseServiceimpl;
import com.xuecheng.content.service.impl.SelectCourseBaseServiceimpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spi.service.contexts.SecurityContext;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 冯佳鑫 又菜又爱学
 * @version 1.0
 * @DATE now()
 * 课程信息编辑接口
 *
 */
@Api(value = "课程信息内容接口" ,tags ="课程信息内容接口")
@RestController
public class CourseBaseInfoController {
    @Autowired
    CourseBaseService courseBaseService;
    @Autowired
    CreateCourseBaseServiceimpl createCourseBaseServiceimpl;
    @Autowired
    SelectCourseBaseServiceimpl selectCourseBaseServiceimpl;
    @PreAuthorize("hasAnyAuthority('xc_teachmanager_course_list')")
    @ApiOperation("课程信息查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(@ApiParam("分页参数") PageParam pageParam,
      @RequestBody(required = false) @ApiParam("课程查询条件") QueryCourseParamDto queryCourseParamDto){
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        String companyId_ = user.getCompanyId();
        long companyId = Long.parseLong(companyId_);
        PageResult<CourseBase> courseBasePageResult = courseBaseService.QueryCoursebaseList(companyId,queryCourseParamDto, pageParam);
        return courseBasePageResult;
    }
    @ApiOperation("新增课程接口")
    @PostMapping("/course")
    public CourseBaseInfoDto createcourse(@RequestBody  AddCourseDto addCourseDto){

     return    createCourseBaseServiceimpl.createcourse(addCourseDto,13134124L);
    }


    @ApiOperation("查询课程信息数据接口")
    @GetMapping("/course/{id}")
    public CourseBaseInfoDto selectCourseBaseInfoDtoByid(@PathVariable Long id ){
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        System.out.println(user);
        CourseBaseInfoDto courseBaseInfoDto = selectCourseBaseServiceimpl.selectCourseBaseInfoDto(id);
        return courseBaseInfoDto;
    }

    @ApiOperation("修改课程信息接口")
    @PutMapping("/course")
    public CourseBaseInfoDto updateCourseBaseInfoDto(@RequestBody EditCourseBaseInfoDto editCourseBaseInfoDto){
        Long companyid =1232141425L;
     return    createCourseBaseServiceimpl.updateCourseBaseInfoDto(companyid,editCourseBaseInfoDto);

    }


}
